@extends('layouts.admin')
@section('title')
  <title>菜单列表页</title>
@endsection
@section('content')
  @include('layouts.left')
  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        菜单列表
        <small>Control panel</small>
      </h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
        <li class="active">Dashboard</li>
      </ol>
    </section>
    <!-- Main content -->
    <section class="content">
      <div class="row">
        <div class="col-xs-12">
          <div class="box">
            <div class="box-header">
              <h3 class="box-title"><a type="button" class="btn btn-block btn-success" href="{{ url('menu') }}/create">添加菜单</a></h3>
            </div>
            <!-- /.box-header -->
            <div class="box-body">
              <table id="example2" class="table table-bordered table-hover">
                <thead>
                <tr>
                  <th><input type="checkbox" name="" value=""></th>
                  <th>id</th>
                  <th>名称</th>
                  <th>级别</th>
                  <th>排序</th>
                  <th>图标</th>
                  <th>操作</th>
                </tr>
                </thead>
                <tbody class="mparent">
                @foreach($dmenus as $dmenu)
                  @if(count($dmenu['child']) == '')
                <tr >
                  <td><input type="checkbox" value="{{$dmenu['id']}}" name="manager[]"></td>
                  <td>{{ $dmenu['id'] }}</td>
                  <td>{{ $dmenu['name'] }}</td>
                  <td>顶级类</td>
                  <td>{{ $dmenu['sort'] }}</td>
                  <td>{{ $dmenu['icon'] }}</td>
                  <td><a href="{{ url('menu') }}/{{ $dmenu['id'] }}"><i class="fa fa-reorder"></i></a>　　<a href="{{url('menu')}}/{{ $dmenu['id'] }}/edit"><i class="fa fa-pencil"></i></a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:;" onclick="menu_delete(this,{{ $dmenu['id'] }})"><i class="fa fa-trash-o"></i></a></td>
                </tr>
                 @else
                  <tr>
                    <td><input type="checkbox" value="{{$dmenu['id']}}" name="manager[]"></td>
                    <td>{{ $dmenu['id'] }}</td>
                    <td>{{ $dmenu['name'] }}</td>
                    <td>顶级类</td>
                    <td>{{ $dmenu['sort'] }}</td>
                    <td>{{ $dmenu['icon'] }}</td>
                    <td><a href="{{ url('menu') }}/{{ $dmenu['id']}}"><i class="fa fa-reorder"></i></a>　　<a href="{{url('menu')}}/{{ $dmenu['id'] }}/edit"><i class="fa fa-pencil"></i></a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:;" onclick="menu_delete(this,{{ $dmenu['id'] }})"><i class="fa fa-trash-o"></i></a></td>
                  </tr>
                  @foreach($dmenu['child'] as $dchild)
                  <tr >
                    <td><input type="checkbox" value="{{$dchild -> id}}" name="manager[]"></td>
                    <td>{{ $dchild -> id }}</td>
                    <td>|--------------{{ $dchild -> name }}</td>
                    <td>二级类</td>
                    <td>{{ $dchild -> sort }}</td>
                    <td>{{ $dchild -> icon }}</td>
                    <td><a href="{{ url('menu') }}/{{ $dchild -> id }}"><i class="fa fa-reorder"></i></a>　　<a href="{{url('menu')}}/{{ $dchild -> id }}/edit"><i class="fa fa-pencil"></i></a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:;" onclick="menu_delete(this,{{ $dchild -> id }})"><i class="fa fa-trash-o"></i></a></td>
                  </tr>
                  @endforeach
                 @endif
                @endforeach
                </tbody>

              </table>
            </div>
            <!-- /.box-body -->
          </div>
        </div>
      </div>
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
  <!-- 在这里 写js函数-->
  <script type="text/javascript">
      function menu_delete(e,id){
          $.ajaxSetup({
              headers:{
                  'X-CSRF-TOKEN':$('meta[name="csrf-token"]').attr('content')
              }
          });
          var tr = $(e).closest("tr");
          if(confirm("确定要删除此条数据吗？"))
          $.ajax({
              url:"{{ url('menu') }}/"+id,
              type:"DELETE",
              data:{id:id},
              success:function(data){
                  if(data.status == 'have'){
                      alert(data.msg);
                  }else if(data.status == 'success'){
                      alert(data.msg);
                      tr.remove();

                  }else{
                      alert(data.msg);
                  }
              },
              dataType:'json'
          });
      }
  </script>
@endsection


